import Pages from '../../pages/pages.vue'
import { searchRecord, showMsg } from '../../../vuex/action'

export default {
  name: 'Record',
  components: {
    'vue-pages': Pages
  },
  data() {
    return {
      customerId: '',
      list: [],
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      }
    }
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xSearchRecord: searchRecord
    }
  },
  ready() {
    this.customerId = this.$route.params.id
    this.search({})
  },
  methods: {
    search({start=this.pages.start, limit=this.pages.limit}) {
      this.xSearchRecord({
        customerId: this.customerId,
        start: start,
        limit: limit
      })
        .then((data) => {
          this.list = data.list
          this.pages.totalPages = Math.ceil(data.totalCount / limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}
